.TH std::chrono::system_clock::to_time_t 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::chrono::system_clock::to_time_t \- std::chrono::system_clock::to_time_t

.SH Synopsis
   static std::time_t to_time_t( const time_point& t ) noexcept;  \fI(since C++11)\fP

   Converts t to a std::time_t type.

   If std::time_t has lower precision, it is implementation-defined whether the value
   is rounded or truncated.

.SH Parameters

   t - system clock time point to convert

.SH Return value

   A std::time_t value representing t.

.SH Example

   Get the current time as a std::time_t two ways.


// Run this code

 #include <chrono>
 #include <ctime>
 #include <iostream>
 #include <thread>
 using namespace std::chrono_literals;

 int main()
 {
     // The old way
     std::time_t oldt = std::time({});

     std::this_thread::sleep_for(2700ms);

     // The new way
     auto const now = std::chrono::system_clock::now();
     std::time_t newt = std::chrono::system_clock::to_time_t(now);

     std::cout << "newt - oldt == " << newt - oldt << " s\\n";
 }

.SH Possible output:

 newt - oldt == 3 s

.SH See also

   from_time_t converts std::time_t to a system clock time point
   \fB[static]\fP    \fI(public static member function)\fP
